package com.ibm.spatiotemp.tools;

import java.util.Date;

import com.ibm.json.java.JSONArray;
import com.ibm.json.java.JSONObject;

public class TrajectoryObject extends STSObject {
	private static final String TYPE = "LineString";
	private JSONArray coordinates = new JSONArray();
	private JSONArray times = new JSONArray();
	
	public void addPoint(long t, double x, double y) {
		JSONArray point = new JSONArray();	
		point.add(new Double(x));
		point.add(new Double(y));
		coordinates.add(point);
		times.add(ThreadLocalDateUtil.formatSTTime(new Date(t)));
	}
	
	public void addPoint(STSPoint p) {
		JSONArray point = new JSONArray();	
		point.add(new Double(p.x));
		point.add(new Double(p.y));
		coordinates.add(point);
		times.add(ThreadLocalDateUtil.formatSTTime(new Date(p.t)));
	}
	

	
	@Override
	public JSONObject toJSONObject() {
		JSONObject json = new JSONObject();
		json.put("type", TYPE);
		json.put("coordinates", coordinates);
		json.put("times", times);				
		return json;
	}

	public JSONArray getCoordinates() {
		return coordinates;
	}

	public JSONArray getTimes() {
		return times;
	}	

}
